home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / MSG Demo 1.4.source Folder / Demo ƒ / Fades ƒ / Four-corner scroll fade.c < prev    next >
Text File  |  1994-04-15  |  5KB  |  145 lines

  1. /**********************************************************************\
  2.  
  3. File:        Four-corner scroll fade.c
  4.  
  5. Purpose:    Graphic effect to fade main window to solid pattern.
  6.             See comments below for more description.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program in a file named "GNU General Public License".
  20. If not, write to the Free Software Foundation, 675 Mass Ave,
  21. Cambridge, MA 02139, USA.
  22.  
  23. \**********************************************************************/
  24.  
  25. #include "timing.h"
  26.  
  27. #define CorrectTime 4
  28. #define theWindowWidth (boundsRect.right-boundsRect.left)
  29. #define theWindowHeight (boundsRect.bottom-boundsRect.top)
  30.  
  31. pascal short FourCornerScrollFade(Rect boundsRect, Pattern *thePattern);
  32.  
  33. /* Four scrolls in one, each confined to a section of the screen which includes
  34.    the center and one side, and all four scrolls moving towards the center.
  35.    Kinda slow on my Mac IIci in 8-bit; fine in 4-bit or fewer. */
  36.    
  37. pascal short FourCornerScrollFade(Rect boundsRect, Pattern *thePattern)
  38. {
  39.     int            x;
  40.     Rect        topdest, bottomdest, leftdest, rightdest;
  41.     Rect        topscrollsource, topscrolldest, bottomscrollsource, bottomscrolldest;
  42.     Rect        leftscrollsource, leftscrolldest, rightscrollsource, rightscrolldest;
  43.     RgnHandle    toprgn,bottomrgn,leftrgn,rightrgn;
  44.     int            cx,cy;
  45.     int            HBoxSize,BoxSize;
  46.     GrafPtr        destGrafPtr;
  47.     
  48.     GetPort(&destGrafPtr);
  49.     
  50.     BoxSize=theWindowHeight/50;
  51.     HBoxSize=theWindowWidth/50;
  52.     
  53.     cx = boundsRect.left + theWindowWidth / 2;
  54.     cy = boundsRect.top + theWindowHeight / 2;
  55.  
  56.     toprgn=NewRgn();
  57.     SetEmptyRgn(toprgn);
  58.     MoveTo(boundsRect.left, boundsRect.top);
  59.     OpenRgn();                               /* top region */
  60.         Line(theWindowWidth,0);
  61.         LineTo(cx,cy);
  62.         LineTo(boundsRect.left, boundsRect.top);
  63.     CloseRgn(toprgn);
  64.     
  65.     bottomrgn=NewRgn();
  66.     SetEmptyRgn(bottomrgn);
  67.     MoveTo(boundsRect.left, boundsRect.bottom);
  68.     OpenRgn();                               /* bottom region */
  69.         Line(theWindowWidth, 0);
  70.         LineTo(cx,cy);
  71.         LineTo(boundsRect.left, boundsRect.bottom);
  72.     CloseRgn(bottomrgn);
  73.     
  74.     leftrgn=NewRgn();
  75.     SetEmptyRgn(leftrgn);
  76.     MoveTo(boundsRect.left, boundsRect.top);
  77.     OpenRgn();                               /* left region */
  78.         Line(0,theWindowHeight);
  79.         LineTo(cx,cy);
  80.         LineTo(boundsRect.left, boundsRect.top);
  81.     CloseRgn(leftrgn);
  82.     
  83.     rightrgn=NewRgn();
  84.     SetEmptyRgn(rightrgn);
  85.     MoveTo(boundsRect.right, boundsRect.top);
  86.     OpenRgn();                               /* right region */
  87.         Line(0, theWindowHeight);
  88.         LineTo(cx,cy);
  89.         LineTo(boundsRect.right, boundsRect.top);
  90.     CloseRgn(rightrgn);
  91.     
  92.     topscrollsource=bottomscrollsource=leftscrollsource=rightscrollsource=
  93.         topdest=bottomdest=leftdest=rightdest=boundsRect;
  94.     
  95.     topscrollsource.bottom-=cy-boundsRect.top+BoxSize;
  96.     topscrolldest = topscrollsource;
  97.     OffsetRect(&topscrolldest, 0, BoxSize);        /* dest. strip for top scroll */
  98.     topdest.bottom=topdest.top+BoxSize;            /* dest. strip for new data on top */
  99.     
  100.     bottomscrollsource.top+=cy-boundsRect.top+BoxSize;
  101.     bottomscrolldest=bottomscrollsource;
  102.     OffsetRect(&bottomscrolldest, 0, -BoxSize);
  103.     bottomdest.top=bottomdest.bottom-BoxSize;
  104.     
  105.     leftscrollsource.right-=cx-boundsRect.left+HBoxSize;
  106.     leftscrolldest=leftscrollsource;
  107.     OffsetRect(&leftscrolldest,HBoxSize,0);
  108.     leftdest.right=leftdest.left+HBoxSize;
  109.     
  110.     rightscrollsource.left+=cx-boundsRect.left+HBoxSize;
  111.     rightscrolldest=rightscrollsource;
  112.     OffsetRect(&rightscrolldest,-HBoxSize,0);
  113.     rightdest.left=rightdest.right-HBoxSize;
  114.     
  115.     /* for each section (top, bottom, left, right) we need to do the scroll part,
  116.     which takes a section of the dest. window and moves it, then we need to copy
  117.     in the new data from the source window */
  118.     for(x = cy - BoxSize; x >= boundsRect.top; x -= BoxSize)
  119.     {
  120.         StartTiming();
  121.         CopyBits(&(destGrafPtr->portBits), &(destGrafPtr->portBits),
  122.                 &topscrollsource, &topscrolldest, 0, toprgn);
  123.         CopyBits(&(destGrafPtr->portBits), &(destGrafPtr->portBits),
  124.                 &bottomscrollsource, &bottomscrolldest, 0, bottomrgn);
  125.         CopyBits(&(destGrafPtr->portBits), &(destGrafPtr->portBits),
  126.                 &leftscrollsource, &leftscrolldest, 0, leftrgn);
  127.         CopyBits(&(destGrafPtr->portBits), &(destGrafPtr->portBits),
  128.                 &rightscrollsource, &rightscrolldest, 0, rightrgn);
  129.         FillRect(&topdest, *thePattern);
  130.         FillRect(&bottomdest, *thePattern);
  131.         FillRect(&leftdest, *thePattern);
  132.         FillRect(&rightdest, *thePattern);
  133.         TimeCorrection(CorrectTime);
  134.     }
  135.     
  136.     FillRect(&boundsRect, *thePattern);        /* in case we missed any bits */
  137.  
  138.     DisposeRgn(toprgn);
  139.     DisposeRgn(bottomrgn);
  140.     DisposeRgn(leftrgn);
  141.     DisposeRgn(rightrgn);
  142.     
  143.     return 0;
  144. }
  145.